package qrcode.create_and_decode;

import cn.hutool.extra.qrcode.QrCodeUtil;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class Creator {

    public static void main(String[] args) {
        new Creator().creator("www.baidu.com", 80, 80, "D:/test.png");
    }

    public void creator(String content, int with, int height, String imgPath) {

        BufferedImage bufferedImage = QrCodeUtil.generate(content, with, height);

        /*Graphics2D graphics2D = bufferedImage.createGraphics();

        graphics2D.setBackground(Color.WHITE);
        graphics2D.clearRect(0, 0, 80, 80);

        graphics2D.setColor(Color.BLACK);

        graphics2D.dispose();*/
        bufferedImage.flush();

        File f = new File(imgPath);

        try {
            ImageIO.write(bufferedImage, "png", f);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
